﻿<UserControl x:Class="SEToolbox.Views.ControlInventory"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:converters="clr-namespace:SEToolbox.Converters"
             xmlns:services="clr-namespace:SEToolbox.Services"
             xmlns:controls="clr-namespace:SEToolbox.Controls"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
             services:DialogService.IsRegisteredView="True">
    <UserControl.Resources>
        <converters:ResouceToImageConverter x:Key="ResouceToImageConverter"/>
        <converters:DDSConverter x:Key="DDSConverter"/>
    </UserControl.Resources>
    <DockPanel>
        <Menu DockPanel.Dock="Top">
            <Menu.ItemsPanel>
                <ItemsPanelTemplate>
                    <DockPanel HorizontalAlignment="Stretch" Height="22"/>
                </ItemsPanelTemplate>
            </Menu.ItemsPanel>
            <TextBlock ToolTip="Inventory Volume">
                <Run Text="{Binding TotalVolume, StringFormat='{}{0:N}'}"/>
                <Run Text="/"/>
                <Run Text="{Binding MaxVolume, StringFormat='{}{0:N}'}"/>
                <Run Text=" L"/>
            </TextBlock>
            <MenuItem Header="Add" Style="{StaticResource ToolBarTopMenuitem}" Command="{Binding AddItemCommand}">
                <MenuItem.Icon>
                    <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=add2}" />
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem Header="Delete" Style="{StaticResource ToolBarTopMenuitem}" Command="{Binding DeleteItemCommand}">
                <MenuItem.Icon>
                    <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=delete2}" />
                </MenuItem.Icon>
            </MenuItem>
            <Separator HorizontalAlignment="Left" Width="4"/>
        </Menu>
        <Grid>
            <controls:MyDataGrid AutoGenerateColumns="False" ItemsSource="{Binding Items, UpdateSourceTrigger=PropertyChanged}" CanUserDeleteRows="False" CanUserAddRows="False" SelectedItem="{Binding SelectedRow}" CanUserSortColumns="False">
                <DataGrid.InputBindings>
                    <KeyBinding Key="Insert" Command="{Binding AddItemCommand}" />
                    <KeyBinding Key="Delete" Command="{Binding DeleteItemCommand}" />
                </DataGrid.InputBindings>
                <DataGrid.Columns>
                    <DataGridTemplateColumn Header="Icon">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Image Width="16" Height="16" Source="{Binding Path=TextureFile, Converter={StaticResource DDSConverter}, ConverterParameter='16,16'}" SnapsToDevicePixels="True" Margin="0,0,2,0" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTextColumn Header="Name" Binding="{Binding FriendlyName}" IsReadOnly="True" />
                    <DataGridTextColumn Header="Mass (Kg)" Binding="{Binding Mass, StringFormat='{}{0:#,###0.000}'}" IsReadOnly="True"/>
                    <DataGridTextColumn Header="Volume (L)" Binding="{Binding Volume, StringFormat='{}{0:#,###0.000}'}" IsReadOnly="True"/>
                    <DataGridTextColumn Header="Amount" ElementStyle="{StaticResource dataGridCellInError}">
                        <DataGridTextColumn.Binding>
                            <Binding Path="Amount" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" ValidatesOnDataErrors="True" >
                                <Binding.ValidationRules>
                                    <converters:RangeRuleDec Min="0.000001" Max="1000000000"/>
                                </Binding.ValidationRules>
                            </Binding>
                        </DataGridTextColumn.Binding>
                    </DataGridTextColumn>
                </DataGrid.Columns>
            </controls:MyDataGrid>
        </Grid>
    </DockPanel>
</UserControl>
